#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,mi,cnt[N],t=0;
struct card{int a,s,p;}r[N];//r[i][0] attack     r[i][1] protection
bool allattacked()
{
    for(int i=1;i<=n;i++)if(r[i].a&&r[i].p)return false;
    return true;
}
void dfs(int x)
{
    if(allattacked())
    {
        int ans=0;
        for(int i=1;i<=n;i++)if(r[i].p)ans++;
        mi=min(ans,mi);
        //printf("***\n");
        //for(int i=1;i<=n;i++)printf("i=%d attack:%d protect:%d\n",i,r[i].a,r[i].p);
        //printf("&&&\n");
        return;
    }
    if(!r[x].p)return;
    for(int i=1;i<=n;i++)if(i!=x&&r[i].p)// r[i] attack r[x]
    {
        r[i].a=0;
        if(r[i].s>r[x].s)r[x].p=0,r[x].a=0;
        dfs(i);
        r[i].a=1,r[x].p=1,r[x].a=1;
        if(mi<=2)return;
    }
}
int main()
{
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    scanf("%d",&n);
    mi=n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&r[i].s);
        r[i].a=1,r[i].p=1;cnt[r[i].s]++;
        if(cnt[r[i].s]==1)t++;
    }
    if(t==2)
    {
        int a=0,b=0,ai=0,bi=0;
        for(int i=1;i<=N;i++)if(cnt[i])
            if(!a)a=cnt[i],ai=i;
            else b=cnt[i],bi=i;//ai<bi
        if(a<b)printf("%d\n",b-a);
        else printf("%d\n",a);
        return 0;
    }
    for(int i=1;i<=n;i++){dfs(i);/*printf("\ni=%d:\n",i);*/}
    printf("%d\n",mi);
    return 0;
}//example 2
//Release 20.03  rev 11997 (2020-03-28 13:56:24)   gcc 9.3.0 Linux/unicode - 64 bit
//Release 20.03  rev 11997 (2020-03-28 13:56:24)   gcc 9.3.0 Linux/unicode - 64 bit
//example 2
//Release 20.03  rev 11997 (2020-03-28 13:56:24)   gcc 9.3.0 Linux/unicode - 64 bit
//Release 20.03  rev 11997 (2020-03-28 13:56:24)   gcc 9.3.0 Linux/unicode - 64 bit\
//example 2
//Release 20.03  rev 11997 (2020-03-28 13:56:24)   gcc 9.3.0 Linux/unicode - 64 bit
//Release 20.03  rev 11997 (2020-03-28 13:56:24)   gcc 9.3.0 Linux/unicode - 64 bit
